/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package epucjr.psicopuc.view.old;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author Rogerio
 */
public class ImageRenderer extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener {

    JTable table;
    JLabel renderLabel;
    JLabel editLabel;
    String text;

    public ImageRenderer(JTable table, int column) {
        super();
        this.table = table;
        renderLabel = new JLabel();
        
//        editLabel.setFocusPainted(false);
//        editLabel.addActionListener(this);
//
       
        TableColumnModel columnModel = table.getColumnModel();
        columnModel.getColumn(column).setCellRenderer(this);
        columnModel.getColumn(column).setCellEditor(this);


    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        renderLabel.setIcon((ImageIcon) value);
        
        return renderLabel;
    }

    public Component getTableCellEditorComponent(
            JTable table, Object value, boolean isSelected, int row, int column) {
        text = (value == null) ? "" : value.toString();
        editLabel.setText(text);
        return editLabel;
    }

    public Object getCellEditorValue() {
        return text;
    }

    public void actionPerformed(ActionEvent e) {
    }

    public JLabel getLbl() {
        return renderLabel;
    }

    public void setLbl(JLabel lbl) {
        this.renderLabel = lbl;
    }
}
